#include "Ventanal.h"

#include <glm\gtc\matrix_transform.hpp>


Ventanal::Ventanal(float ancho, float alto) : m_ancho(ancho), m_alto(alto), m_vidrioexterno(ancho, alto), m_vidriointerno(ancho, alto){ }

void Ventanal::init(const glm::vec3 &DireccionLuz){
	this->m_barral.init(DireccionLuz);

	this->m_vidrioexterno.init(DireccionLuz, "CubeMappingShader.vert", "CubeMappingShader.frag");
	this->m_vidrioexterno.setMaterial( glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(0.2f, 0.2f, 0.2f), 64.0f );
	this->m_vidrioexterno.setCubeMap();

	this->m_vidriointerno.init(DireccionLuz, "TextureShader.vert", "TextureShader.frag");
	this->m_vidriointerno.setMaterial( glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(0.2f, 0.2f, 0.2f), glm::vec3(0.2f, 0.2f, 0.2f), 64.0f );
	this->m_vidriointerno.setTextura("cristal.dds");
}


void Ventanal::renderizar(const glm::mat4 &matVista, const glm::mat4 &matProyeccion, const glm::mat4 &matModelo) const {

	glm::mat4 matModelPlacaExterna = glm::translate(matModelo, glm::vec3(0.0f, 0.0f, 0.0f));
	this->m_vidrioexterno.renderizar(matVista, matProyeccion, matModelPlacaExterna);

	glm::mat4 matModelPlacaInterna = glm::translate(matModelo, glm::vec3(-0.1f, this->m_ancho, 0.0f));
	matModelPlacaInterna = glm::rotate(matModelPlacaInterna, 180.0f, glm::vec3(0.0f, 0.0f, 1.0f));
	this->m_vidriointerno.renderizar(matVista, matProyeccion, matModelPlacaInterna);

	// Cuatro barrales
	glm::mat4 matModelBarral = glm::translate(matModelo, glm::vec3(0.0f, 0.0f, 0.0f));
	this->m_barral.renderizar(matVista, matProyeccion, matModelBarral);

	matModelBarral = glm::translate(matModelo, glm::vec3(0.0f, (this->m_ancho)/3, 0.0f));
	this->m_barral.renderizar(matVista, matProyeccion, matModelBarral);

	matModelBarral = glm::translate(matModelo, glm::vec3(0.0f, 2.0 * (this->m_ancho)/3, 0.0f));
	this->m_barral.renderizar(matVista, matProyeccion, matModelBarral);

	matModelBarral = glm::translate(matModelo, glm::vec3(0.0f, this->m_ancho, 0.0f));
	this->m_barral.renderizar(matVista, matProyeccion, matModelBarral);

}